home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / put.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-02  |  4.8 KB  |  190 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record
  3.  * Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
  4.  * 
  5.  * This file is part of ED.
  6.  * 
  7.  * ED is free software; you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation.
  9.  * 
  10.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  13.  * 
  14.  * You should have received a copy of the GNU General Public License along with ED
  15.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  16.  * Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18. #include "opsys.h"
  19.  
  20. #include <stdio.h>
  21.  
  22. #define BUFFERSIZE 64
  23.  
  24. #include "emul_def.h"
  25. #include "handy.h"
  26.  
  27. static Char enabled = 1;
  28. static Char buf[BUFFERSIZE+1];
  29. static Char *cur = buf,*end = &buf[BUFFERSIZE];
  30.  
  31. /******************************************************************************\
  32. |Routine: put
  33. |Callby: init_term put
  34. |Purpose: Basic output routine. Puts a string to the terminal. Should not be
  35. |         used by software sharing this library, use putz instead.
  36. |Arguments:
  37. |    string is the string to put to the terminal.
  38. \******************************************************************************/
  39. void put(string)
  40. Char *string;
  41. {
  42.     register Char *b;
  43.  
  44.     if(!enabled)
  45.         return;
  46.     if(BRAINDEAD)
  47.         return;
  48.     b = cur;
  49.     while((*b++ = *string++))
  50.         if(b == end)
  51.         {
  52.             ttyput(buf);
  53.             b = buf;
  54.         }
  55.     cur = --b;
  56. }
  57.  
  58. /******************************************************************************\
  59. |Routine: putout
  60. |Callby: cfg command help imalloc init_term inquire put wincom word_fill
  61. |Purpose: Forces dumping of buffered output to the terminal.
  62. |Arguments:
  63. |    none
  64. \******************************************************************************/
  65. void putout()
  66. {
  67.     short *screen;
  68.     register Char *s,*a;
  69.     Int i;
  70.  
  71.     if(!BRAINDEAD)
  72.     {
  73.         if(cur != buf)
  74.         {
  75.             *cur = 0;
  76.             if(enabled)
  77.                 ttyput(buf);
  78.             cur = buf;
  79.         }
  80.     }
  81.     else if(enabled && EMU_CURROW >= 0)    /* braindead terminal */
  82.     {
  83.         ttygetsb(&screen);    /* get screen base from ttyput routines */
  84.         s = EMU_SCREEN;
  85.         a = EMU_ATTRIB;
  86.         for(i = 1; i <= EMU_NCOL * EMU_NROW; i++)
  87.             if(*a++)
  88.                 *screen++ = 0x7000 | (Uchar)*s++;
  89.             else
  90.                 *screen++ = 0x700 | (Uchar)*s++;
  91.         ttyscreen(EMU_CURROW,EMU_CURCOL);
  92.     }
  93. }
  94.  
  95. /******************************************************************************\
  96. |Routine: putz
  97. |Callby: cfg command edit help init_term inquire load_key match_paren paint paint_window ref_window remove_win select slip_message unselect
  98. |Purpose: High-level output routine; puts a string to the terminal.
  99. |Arguments:
  100. |    string is the string to put out.
  101. \******************************************************************************/
  102. void putz(string)
  103. register Char *string;
  104. {
  105.     register Char *s,*a;
  106.     register Int nskip,column;
  107.     Char buf[2],skipbuf[5];    /* skipbuf is used to store characters that we may later have to spit out to reposition the cursor */
  108.     Int off;
  109.  
  110.     buf[1] = '\0';
  111.     off = EMU_NCOL * EMU_CURROW + EMU_CURCOL;
  112.     s = EMU_SCREEN + off;
  113.     a = EMU_ATTRIB + off;
  114.     for(column = EMU_CURCOL,nskip = 0;*string && column < EMU_NCOL;string++,s++,a++,column++)
  115.         if(*s == *string && *a == EMU_CURATT)
  116.         {
  117.             if(nskip <= 3)
  118.                 skipbuf[nskip] = *s;
  119.             nskip++;
  120.         }
  121.         else
  122.         {
  123.             if(nskip > 4)
  124.                 right(nskip);
  125.             else if(nskip > 0)
  126.             {
  127.                 skipbuf[nskip] = '\0';
  128.                 put(skipbuf);
  129.             }
  130.             nskip = 0;
  131.             buf[0] = *s = *string;
  132.             *a = EMU_CURATT;
  133.             put(buf);
  134.         }
  135.     if(nskip > 0)
  136.         right(nskip);
  137.     EMU_CURCOL = min(column,EMU_NCOL - 1);
  138. }
  139.  
  140. /******************************************************************************\
  141. |Routine: putoff
  142. |Callby: edit init_term parse_fnm word_fill
  143. |Purpose: Turns off all terminal i/o.
  144. |Arguments:
  145. |    none
  146. \******************************************************************************/
  147. void putoff()
  148. {
  149.     putout();
  150.     enabled = 0;
  151. }
  152.  
  153. /******************************************************************************\
  154. |Routine: puton
  155. |Callby: edit init_term word_fill
  156. |Purpose: Resumes terminal i/o.
  157. |Arguments:
  158. |    none
  159. \******************************************************************************/
  160. void puton()
  161. {
  162.     putout();
  163.     enabled = 1;
  164. }
  165.  
  166. /******************************************************************************\
  167. |Routine: puttest
  168. |Callby: edit init_term insert paint
  169. |Purpose: Test whether terminal i/o is enabled.
  170. |Arguments:
  171. |    none
  172. \******************************************************************************/
  173. Int puttest()
  174. {
  175.     return(enabled);
  176. }
  177.  
  178. /******************************************************************************\
  179. |Routine: putpurge
  180. |Callby: parse_fnm
  181. |Purpose: Make it as though nothing has been passed to put() yet.
  182. |Arguments:
  183. |    none
  184. \******************************************************************************/
  185. void putpurge()
  186. {
  187.     cur = buf;
  188. }
  189.  
  190.